<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
	
<%@page import="com.lovo.bbs.vo.*,com.lovo.bbs.bo.*,java.util.*"%>

<%	
    String asBoardId = request.getParameter("boardSelect");//搜索范围
    ArrayList<ForumVo> forumList=null;
    
    if(!"0".equals(asBoardId)&&asBoardId!=null){//显示指定板块下的论坛
      forumList = new ForumBo().getForumByBoardID(Integer.parseInt(asBoardId)); 
    }else {//显示所有论坛
      forumList = (ArrayList<ForumVo>)application.getAttribute("forumList");
    }
    
    ArrayList<BoardVo> boardList = (ArrayList<BoardVo>) application.getAttribute("boardList");
	HashMap<Integer,BoardVo> boardMap = new BoardBo().getBoardMap(boardList);
	
	//请求页
	String queryPages = (String)request.getAttribute("queryPage");
	if(queryPages==null||"".equals(queryPages)||"0".equals(queryPages)){
	  queryPages="1";
	}
	int queryPage=Integer.parseInt(queryPages);
	
	int forumCount =forumList.size();
	int pageNum = (forumCount % 20 == 0) ? (forumCount / 20) : (forumCount / 20 + 1);
	Iterator it, it1;
%>
<html>
	<head>
		<link href="../../../css/admin.css" rel="stylesheet" type="text/css" />
		<script type="text/javascript" src="../../../js/wbs_admin.js"></script>
		<script type="text/javascript">
		function preQuery(){
			document.frmMain.action="forumManageQueryPage.jsp";
			document.frmMain.submit();
		}
		function preInsert(){
			document.frmMain.opType.value=1;
			document.frmMain.action="forumManageUpdatePage.jsp";
			document.frmMain.submit();
		}
		function preMod(forumid,boardid,forumname,forumread){
			document.frmMain.forumid.value=forumid;
			document.frmMain.boardid.value=boardid;
			document.frmMain.forumname.value=forumname;
			document.frmMain.forumread.value=forumread;

			document.frmMain.opType.value=2;
			
			document.frmMain.action="forumManageUpdatePage.jsp";
			document.frmMain.submit();
		}
		
		function preDel(forumid,boardid,forumname,forumread){
			document.frmMain.forumid.value=forumid;
			document.frmMain.boardid.value=boardid;

			document.frmMain.forumname.value=forumname;
			document.frmMain.forumread.value=forumread;

			document.frmMain.opType.value=3;
			
			document.frmMain.action="forumManageUpdatePage.jsp";
			document.frmMain.submit();
		}
		
		
				
		</script>
	</head>
	<body>
	  <form name="frmMain" method="post">
		<table class="navigation" style="width:98%" align="center">
			<tr>
				<td>
					当前位置: 论坛管理
				</td>
			</tr>
		</table>
		<fieldset style="width:98%" align="center">
			<table align="left">
				<tr>
					<td>
						&nbsp;
					</td>
				</tr>
			</table>
			<br>
			<table align="center">
				<tr>
					<td align="center" valign="middle">
						按版块查询:
						<select name="boardSelect">
						<option value="0">
								默认
						</option>
							<%	if (boardList == null) {
									boardList = new ArrayList();
								}
								it1 = boardList.iterator();
								if (it1 != null) {
									while (it1.hasNext()) {
										BoardVo boardData = (BoardVo) (it1.next());
							%>
							<option value="<%=boardData.getBoardID()%>"><%=boardData.getBoardName()%></option>
							<%}}%>
						</select>
					</td>
					<td>
						<input type="button" class="button" value=" 查询 " onclick="preQuery()">
					</td>
				</tr>
			</table>
		</fieldset>
			<table border="0" cellspacing="0" cellpadding="0" width="98%"  align="center">
				<tr>
					<td>
						<table width="100%" border="0" cellspacing="0" cellpadding="4">
							<tr>
								<td id="content_bar">
									<a class="content_total">论坛总数: <%=forumCount%> ,第<%=queryPage%>页 总<%=pageNum%>页 </a>
									<%	for (int i = 1; i <= pageNum; i++) {
											if (i == queryPage) {
									%>
									<a class="content_pasges_c"><%=i%> </a>
									<%} else {%>
									<a class="content_pasges_a"	href="forumManageQueryPage.jsp?queryPage=<%=i%>"><%=i%></a>
									<%	}}%>
									<input type="button" value=" 增加新论坛 " class="button" style="float:right" onclick="preInsert();">
								</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td>
						<table border="0" cellspacing="1" cellpadding="4" class="tableborder" style="width:100%; background-color:#CCFFFF; border:#99FFCC 0px solid">
							<tr class="header">
								<td width="20%">
									论坛名称
								</td>
								<td width="10%">
									所属版块
								</td>
								
								<td width="30%">
									论坛介绍
								</td>
							
								<td width="10%">
									操作
								</td>
							</tr>
							<%
								int forumid, boardid, forumorder;
								String forumname,forumread,forummaster;
								if (forumList == null) {
									forumList = new ArrayList();
									System.out.println("论坛数据为空");
								}
								it = forumList.iterator();
								if (it != null) {
									while (it.hasNext()) {
										ForumVo forumData = (ForumVo) (it.next());
										forumid = forumData.getForumID();
										boardid = forumData.getBoardID();
										forumname = forumData.getForumName();
										String theBoardName = boardMap.get(boardid).getBoardName();
										forumread = forumData.getAboutForum();
							%>
							<tr class="row">
								<td>
									<%=forumname%>
								</td>
								<td>
									<%=theBoardName%>
								</td>
								<td align="left">
									<%=forumread%>
								</td>
								<td>
									<input type="button" value=" 修改 " class="button" onclick="preMod('<%=forumid%>','<%=boardid%>','<%=forumname%>','<%=forumread%>')">
									<input type="button" value=" 删除 " class="button" style="color:#ff0000;" onclick="preDel('<%=forumid%>','<%=boardid%>','<%=forumname%>','<%=forumread%>')">
								</td>
							</tr>
							<%}}%>
						</table>
					</td>
				</tr>
			</table>
			<br>
			<input type="hidden" name="forumid" value="">
			<input type="hidden" name="forumname" value="">
			<input type="hidden" name="boardid" value="">
			<input type="hidden" name="forumread" value="">
			
			<input type="hidden" name="opType" value="">
			
			<input type="hidden" name="queryPage" value="<%=queryPage%>">
		</form>
	</body>
</html>
